﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using Follow.Utils;
using Follow.Model;
using System.Transactions;
using Follow.Common;
using System.Data;

namespace Follow.DataAccess
{
    public class StatusFollowDAO
    {
        private SqlDataReader reader = null;
        private SqlConnection conn = null;
        private SqlCommand cmd = null;

        public StatusFollowDAO()
        {
            conn = ConnectionUtils.getConnection();
        }

        public IList<StatusFollow> findAll()
        {
            IList<StatusFollow> status = new List<StatusFollow>();
            String sqlCommand;
            try
            {
                conn.Open();

                sqlCommand = " select * from statusfollow order by idstatus ";
                cmd = new SqlCommand(sqlCommand, conn);
                reader = cmd.ExecuteReader();

                while (reader.Read())
                {
                    StatusFollow s = new StatusFollow();
                    s.IDStatus = reader.GetInt32(0);
                    s.DescricaoStatus = reader.GetString(1);
                 
                    status.Add(s);
                }
            }

            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }

                if (conn != null)
                {
                    conn.Close();
                }
            }
            return status;

        }




        public IList<StatusFollow> findByStatusAtual(int idProposta, int idFollowUp)
        {
            IList<StatusFollow> statusfollow = new List<StatusFollow>();

            try
            {
                conn.Open();

                String sqlCommand = "spRetornaStatus";
                cmd = new SqlCommand(sqlCommand, conn);

                cmd.CommandType = CommandType.StoredProcedure;

                cmd.Parameters.Add("@idProposta", idProposta);
                cmd.Parameters.Add("@idFollowUp", idFollowUp);

                reader = cmd.ExecuteReader();

                while (reader.Read())
                {
                    StatusFollow s = new StatusFollow();
                    s.IDStatus = reader.GetInt32(0);
                    s.DescricaoStatus = reader.GetString(1);

                    statusfollow.Add(s);
                }
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }

                if (conn != null)
                {
                    conn.Close();
                }
            }
            return statusfollow;
        }
    }
}